extends Sprite2D

@onready var hurt_componet: HurtComponet = $HurtComponet
@onready var damage_component: DamageComponent = $DamageComponent
var log_scene = preload("res://scenes/object/rocks/stone.tscn")

func _ready() -> void:
	hurt_componet.hurt.connect(on_hurt)
	damage_component.max_damage_reached.connect(on_max_damage_reached)

func on_hurt(hit_damage:int)->void:
	damage_component.apply_damage(hit_damage)
	material.set_shader_parameter("shake_intensity",0.3);
	await  get_tree().create_timer(0.5).timeout
	material.set_shader_parameter("shake_intensity",0.0);
	
func on_max_damage_reached()-> void:
	call_deferred("add_stone_sscene")
	queue_free()
	
func add_stone_sscene()->void:
	var log_instance =log_scene.instantiate() as Node2D
	log_instance.global_position = global_position
	get_parent().add_child(log_instance)
